//
//  ChangeLoginViewController.m
//  盘盈贷
//
//  Created by iOS on 15/4/1.
//  Copyright (c) 2015年 Yunpeng Technologies. All rights reserved.
//

#import "ChangeLoginViewController.h"
#import "AFHTTPRequestOperationManager.h"
@interface ChangeLoginViewController ()
{
    UITextField *old;
    UITextField *new;
    UITextField *again;
}
@end

@implementation ChangeLoginViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"更改登陆密码";
        self.view.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    CGFloat height = self.view.frame.size.height;
    CGFloat width = self.view.frame.size.width;
    UILabel *yuan = [[UILabel alloc] initWithFrame:CGRectMake(10, height / 6.2, 120, 30)];
    yuan.font = [UIFont systemFontOfSize:14];
    yuan.text = @"登陆密码 :";
    [self.view addSubview:yuan];
    [yuan release];
    
    old = [[UITextField alloc] initWithFrame:CGRectMake(180,  height / 5.1, 210, 40)];
    old.placeholder = @"请输入您的密码";
    old.center = CGPointMake(200, height / 5.1);
    [old.layer setCornerRadius:4];
    [old.layer setBorderWidth:1];
    old.secureTextEntry = YES; //密码
    old.textColor = [UIColor grayColor];
    old.borderStyle = UITextBorderStyleRoundedRect;
    old.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:old];
    [old release];
    
    UILabel *xin = [[UILabel alloc] initWithFrame:CGRectMake(10, height / 3.8, 120, 30)];
    xin.font = [UIFont systemFontOfSize:14];
    xin.text = @"再次输入密码:";
    [self.view addSubview:xin];
    [xin release];
    
    new = [[UITextField alloc] initWithFrame:CGRectMake(180,  height / 3.6, 210, 40)];
    new.center = CGPointMake(200, height / 3.5);
    [new.layer setCornerRadius:4];
    new.placeholder = @"请再次输入密码";
    [new.layer setBorderWidth:1];
    new.secureTextEntry = YES; //密码
    new.textColor = [UIColor grayColor];
    new.borderStyle = UITextBorderStyleRoundedRect;
    new.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:new];
    [new release];
    
//    UILabel *last = [[UILabel alloc] initWithFrame:CGRectMake(10, height / 2.9, 120, 30)];
//    last.text = @"确认密码:";
//    [self.view addSubview:last];
//    [last release];
//    
//    again = [[UITextField alloc] initWithFrame:CGRectMake(10,  height / 2.3, width / 1.2, 40)];
//    again.center = CGPointMake(width / 2, height / 2.3);
//    [again.layer setCornerRadius:4];
//    [again.layer setBorderWidth:1];
//    again.secureTextEntry = YES; //密码
//    again.textColor = [UIColor grayColor];
//    again.borderStyle = UITextBorderStyleRoundedRect;
//    again.clearButtonMode = UITextFieldViewModeWhileEditing;
//    [self.view addSubview:again];
//    [again release];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, height / 2.5, width / 1.2, 40);
    button.center = CGPointMake(width / 2, height / 2.5);
    button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor redColor];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
- (void)next:(id)sender {
   
    NSString *str = [NSString stringWithFormat:@"http://www.cloudpeng.com:8102/account/ChangePassword?strusername=%@", self.name];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([[[responseObject firstObject] objectForKey:@"value"]isEqualToString:@"true"]) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"修改成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
        NSLog(@"issuccess:%@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"~~~~~~~%@",error);
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
